package com.gz.mylife.util;


import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
 * 
 * @author admin
 *
 */
public class NetworkUtil {


	public static boolean IsNetworkAvailble(Context context) {
		try {
			ConnectivityManager connectivity = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);

			if (connectivity != null) {
				NetworkInfo info = connectivity.getActiveNetworkInfo();
				if ((info != null) && (info.isConnected())) {
					if (info.getState() == NetworkInfo.State.CONNECTED) {
						return true;
					} else {
						return false;
					}
				}
			}
		} catch (Exception e) {
			return false;
		}
		return false;
	}
	/**
	 * 判断是否有网
	 * @param context
	 * @return
	 */
	public static boolean isNetworkConnected(Context context) {
		if (context != null) {
			ConnectivityManager mConnectivityManager = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
			if (mNetworkInfo != null) {
				return mNetworkInfo.isAvailable();
			}
		}
		return false;
	}

}
